//------------------------------------------------
//		Display7Seg.c
//	7 segment display library
//	Arthur Benemann 29/12/2011
//------------------------------------------------
//
//	Description:
//
//-----------------------------------------------
//
//	Requeriments:
// 	8 I/O pins with a charliplexed 7segment display
//
//-----------------------------------------------


#include "../Compiler.h"
//#include "../HardwareProfile.h"

unsigned char displayCnt = 7;
char display[8] = {1,2,3,4,5,6,7,8};

const unsigned char displayMap[10][8]= {
	{0x80&0XFE, 0x80&0xFD, 0x80&0xFB, 0x80&0xF7, 0x80&0xEF, 0x80&0xDF, 0x80&0xBF, 0x40&0x7F}, // 0
	{0xF3&0XFE, 0xF3&0xFD, 0xF5&0xFB, 0xF9&0xF7, 0xF9&0xEF, 0xF9&0xDF, 0xF9&0xBF, 0xF9&0x7F}, // 1
	{0x48&0XFE, 0x48&0xFD, 0x48&0xFB, 0x44&0xF7, 0x44&0xEF, 0x44&0xDF, 0x24&0xBF, 0x24&0x7F}, // 2
	{0x60&0XFE, 0x60&0xFD, 0x60&0xFB, 0x60&0xF7, 0x60&0xEF, 0x50&0xDF, 0x30&0xBF, 0x30&0x7F}, // 3
	{0x32&0XFE, 0x31&0xFD, 0x31&0xFB, 0x31&0xF7, 0x29&0xEF, 0x19&0xDF, 0x19&0xBF, 0x19&0x7F}, // 4
	{0x24&0XFE, 0x24&0xFD, 0x22&0xFB, 0x22&0xF7, 0x22&0xEF, 0x12&0xDF, 0x12&0xBF, 0x12&0x7F}, // 5
	{0x04&0XFE, 0x04&0xFD, 0x02&0xFB, 0x02&0xF7, 0x02&0xEF, 0x02&0xDF, 0x02&0xBF, 0x02&0x7F}, // 6
	{0xF0&0XFE, 0xF0&0xFD, 0xF0&0xFB, 0xF0&0xF7, 0xF8&0xEF, 0xF8&0xDF, 0xF8&0xBF, 0xF8&0x7F}, // 7
	{0x00&0XFE, 0x00&0xFD, 0x00&0xFB, 0x00&0xF7, 0x00&0xEF, 0x00&0xDF, 0x00&0xBF, 0x00&0x7F}, // 8
	{0x20&0XFE, 0x20&0xFD, 0x20&0xFB, 0x20&0xF7, 0x20&0xEF, 0x10&0xDF, 0x10&0xBF, 0x10&0x7F}, // 9
};

void updateDisplay()
{
	if(displayCnt)
		displayCnt--;
	else
		displayCnt = 7;

	LATE = 0;
	TRISE = displayMap[(int)display[(int)displayCnt]][(int)displayCnt];
	LATE = 1<<displayCnt;	
}
